<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>库存盘点管理</title>
<meta name="decorator" content="default" />
<style type="text/css">
	table thead tr {
		background: rgb(190, 190, 194);
	}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		$("#contentTable tbody tr").click(function() {
			$("#contentTable tbody tr").removeClass(
					"select_active");
			$(this).addClass("select_active");
			var checkTd = $("#checkbox-" + this.id);
			checkTd.attr("checked",!checkTd.attr("checked"));
			var isAll = true;
			 $('.storeProduct').each(function(){
				 if(!this.checked){
					 isAll = false;
				 }
			 });
			 $("#selectAll").attr("checked",isAll);
		});
		$("#contentTable thead tr").click(function() {
			 $("#selectAll").click();
		});
		$("#addSelect").click(function() {
			var selectIds = "";
			$('.storeProduct').each(function(){
				 if(this.checked){
					 selectIds += this.value + ",";
				 }
			});
			if (!selectIds) {
				showTip("未选择产品,请选择");
				return;
			}
			if (selectIds) {
				var url = "${ctx}/inventory/storeInventoryCheck/saveProduct?productIds="
						+ selectIds;
				window.location.href = url;
			}
		});
		$("#selectAll").click(function(e){
			 $('.storeProduct').attr("checked",this.checked);
			 e.stopPropagation();
		});
		$(".storeProduct").click(function(e){
			var isAll = true;
			 $('.storeProduct').each(function(){
				 if(!this.checked){
					 isAll = false;
				 }
			 });
			 $("#selectAll").attr("checked",isAll);
			 e.stopPropagation();
		});
	});
</script>
</head>
<body>
	<div class="form-input">
		<tags:message content="${message}" />
		<div class="icon-buttons">
			<a id="btnBack" data-role="button"  data-icon="back" data-iconpos="notext"  data-inline="true" href="${ctx}/inventory/storeInventoryCheck/detailList">返回</a>
			<input id="addSelect" type="button"  data-icon="check" data-iconpos="notext"  data-inline="true" value="添加选中产品">
		</div>
		<h2  style="text-align: center;">产品选择</h2>
		<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
			<thead>
				<tr>
					<th>
						<c:if test="${not empty sspList}">
							<input type="checkbox" id="selectAll" data-inline="true" checked value="all"/>
						</c:if>
					</th>
					<th>产品分类</th>
					<th>产品名称</th>
					<th>规格</th>
					<th>零售价</th>
					<th>数量</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${empty sspList}">
					<tr>
						<td colspan="6" style="text-align: center;">库存中的产品已经全部被选择</td>
					</tr>
				</c:if>
				<c:if test="${not empty sspList}">
					<c:forEach items="${sspList}" var="storeProduct">
						<tr id="${storeProduct.id}">
							<td><input type="checkbox" id="checkbox-${storeProduct.id}" checked class="storeProduct" value="${storeProduct.id}"/></td>
							<td>${storeProduct.storeSelfProduct.storeSelfProductCategory.name}</td>
							<td>${storeProduct.storeSelfProduct.name}</td>
							<td>${storeProduct.storeSelfProduct.spec}</td>
							<td>${storeProduct.storeSelfProduct.retail_price}</td>
							<td>${storeProduct.amount}</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
	</div>
</body>
</html>
